#include "main.h"

/*************************************************
takes a number and draws it on the screen at x,y
*************************************************/
void CNum::drawnumber(int num, int x, int y)
{
	int count = 0;
	bool start = false;
	int a;
	int number[7] = {0};
	int temp[7] = {0};

	temp[0] = num/1000000;
	num = num-((num/1000000)*1000000);
	temp[1] = num/100000;
	num = num-((num/100000)*100000);
	temp[2] = num/10000;
	num = num-((num/10000)*10000);
	temp[3] = num/1000;
	num = num-((num/1000)*1000);
	temp[4] = num/100;
	num = num-((num/100)*100);
	temp[5] = num/10;
	num = num-((num/10)*10);
	temp[6] = num/1;

	for(int loop = 0; loop < 7; loop++)
	{
	
		if(temp[loop] != 0 && start != true || (loop == 6 && start != true))
		{
			start = true;
			a = loop;
		}
		if(start == true)
		{
			number[loop-a] = temp[loop];
			count++;
		}
	}
	

	for(int loop2 = 0; loop2 < count; loop2++)
	{

		glBindTexture(GL_TEXTURE_2D,digits[number[loop2]]);

		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)x, (GLfloat)y,  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)x+24*scale, (GLfloat)y,  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)x+24*scale,  (GLfloat)y+24*scale,  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)x,  (GLfloat)y+24*scale,  0.0f);	// Top Left Of The Texture and Quad
		glEnd();

		x+=(16*scale);
	}	

}


/*************************************************
loads the sprites for each digit
*************************************************/
void CNum::loaddigits()
{
	char *numfiles[] =
	{ 
		"sprite/zero.bmp",
		"sprite/one.bmp",
		"sprite/two.bmp",
		"sprite/three.bmp",
		"sprite/four.bmp",
		"sprite/five.bmp",
		"sprite/six.bmp",
		"sprite/seven.bmp",
		"sprite/eight.bmp",
		"sprite/nine.bmp"	
	};	
	
	for(int index = 0; index < 10; index++)
	{
		digits[index] = LoadGLTextures(numfiles[index]);

	}

}